<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Instansi extends Admin_Controller
{
	public function __construct(){
		parent::__construct();
		$this->module = strtolower(__CLASS__);	
		check_user('Instansi');
	}
	
	public function index()
	{		
		check_user('Data ');
		$allow_edit_pegawai= check_user('Edit instansi',false);
		$allow_add_pegawai= check_user('Tambah instansi',false);
		$allow_delete_pegawai= check_user('Delete instansi',false);
		
		
		$this->crud->set_table('sp_pegawai');
		$this->crud->set_primary_key('pegawai_id');
		$this->crud->set_subject('Data pegawai');
		$this->crud->required_fields('nip'
									,'nip_lama'
									,'nama'
									,'jenis_kelamin'
									,'tempat_lahir'
									,'tanggal_lahir'
									,'agama'
									,'alamat'
									,'kodepos'
									,'jenis_pegawai'
									,'kedudukan_pegawai'
									,'status_pegawai'
									,'photo_pegawai'
									,'no_akta_lahir'
									,'no_identitas'
									,'gol_darah'
									,'berat_badan'
									,'tinggi_badan'
									,'warna_kulit'
									,'status_kepemilikan_rumah'
									);
		$this->crud->set_field_upload('photo_pegawai','files/pegawai');
		$this->crud->set_relation('jenis_kelamin','sp_jenis_kelamin','jk_nama');		
		$this->crud->set_relation('agama','sp_agama','agama_nama');	
		$this->crud->set_relation('jenis_pegawai','sp_jenis_pegawai','jenis_pegawai');	
		$this->crud->set_relation('kedudukan_pegawai','sp_kedudukan_pegawai','kedudukan_pegawai');
		$this->crud->set_relation('status_pegawai','sp_status_pegawai','status_name');
		$this->crud->set_relation('status_kepemilikan_rumah','sp_status_kepemilikan_rumah','status_rmh_name');
		//$this->crud->set_relation('tempat_lahir','sp_lokasi','lokasi_nama',array('jenis' => 'P'));
		$this->crud->columns('id','nip','nama','gelar_depan','gelar_belakang','alamat');
		
		$this->crud->callback_add_field('tempat_lahir', array($this,'tempat_lokasi'));

		if( !$allow_add_pegawai ){
			$this->crud->unset_add();
		}
		
		if( !$allow_edit_pegawai ){
			$this->crud->unset_edit();
		}
		
		if( !$allow_delete_pegawai ){
			$this->crud->unset_delete();
		}
		
		$this->crud->add_action('Data riwayat', $this->icon->fa['tags'], 'pegawai/riwayat','ui-icon-plus');
		$this->crud->set_field_upload('image','files/pegawai');
		$output = $this->crud->render();
		
		$data['output'] = $output;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$this->load->view($this->layout_content,$data);		
	}	
}